{include file='head'/}
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <blockquote class="layui-elem-quote pluginCenter"> 插件管理：
            <span style="margin-left: 12px">在线安装、卸载、禁用、启用、配置、升级插件，插件升级前请做好备份并确保服务器读写权限正确</span>
            <span class="fr"><i class="layui-icon fa-user" onclick="layui.plugin.clearLogin();"
                                title="退出登录"></i></span>
        </blockquote>
        <table id="admin_table" lay-filter="admin_table"></table>
    </div>
</div>
<script type="text/html" id="add_toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md {php}if(!check_auth(__url('plugin/index/add'))){ echo 'layui-hide';} {/php}"
            data-open="{:__url('plugin/index/add')}"
            data-title="创建插件" data-reload="2">
        <i class="layui-icon layui-icon-add-1"></i>
        创建插件
    </button>
</script>

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{d.plugin_path}}" lay-skin="switch" lay-text="启用|禁用"
           lay-filter="switchStatus"
           data-href="{:__url('plugin/index/enable')}?name={{d.plugin_path}}" {{d.status== 1 ? 'checked' : '' }} />
</script>

<script type="text/html" id="barDemo">
    {{#  if(d.enable =='1'){ }}
    {{#  if(d.is_config =='1'){ }}
    <button class="pear-btn pear-btn-sm pear-btn-lvse" title="设置" data-reload="1"
            data-open="{:__url('plugin/index/config')}?name={{d.plugin_path}}"
            data-title="设置">
        <i class="layui-icon layui-icon-set"></i>
    </button>
    {{#  } }}
    <button class="pear-btn pear-btn-fense pear-btn-sm" title="卸载" data-reload="1"
            data-confirm="{:__url('plugin/index/uninstall')}?name={{d.plugin_path}}"
            data-title="<b>温馨提示</b><br>
            确认卸载 【{{d.plugin_path}}】 吗？<br>
            1、卸载前请自行备份插件数据库 ！<br>
            2、数据库表删除后无法找回 ！<br>
            3、如果有角色组权限设置，请重新更新角色组权限<br>">
        <i class="layui-icon layui-icon-close"></i>
    </button>
    {{#  } else { }}
    <button class="pear-btn pear-btn-primary pear-btn-sm" title="安装" data-reload="1"
            data-confirm="{:__url('plugin/index/install')}?name={{d.plugin_path}}"
            data-title="确定要安装吗？">
        <i class="layui-icon layui-icon-ok"></i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" title="删除" data-reload="1"
            data-delete="{:__url('plugin/index/delete')}?name={{d.plugin_path}}"
            data-title="您确定要删除插件吗？">
        <i class="layui-icon layui-icon-delete"></i>
    </button>
    {{#  } }}
</script>

{include file='footer'/}
<script>
  layui.use(['table', 'jquery', 'drawer'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    table.render({
      elem: '#admin_table'
      , toolbar: '#add_toolbar'
      , defaultToolbar: [{
        layEvent: 'refresh',
        icon: 'layui-icon-refresh',
        title: '刷新'
      }, 'filter']
      , method: 'get'
      , url: "{:__url('plugin/index/index')}"
      , parseData: function (res) {
        return {
          "code": res.code_lay,
          "msg": res.msg,
          "count": res.count,
          "data": res.data
        };
      }
      , cellMinWidth: 100
      , cols: [[
        {type: 'numbers'}
        , {field: 'name', title: '插件标识', align: 'center', width: 100}
        , {field: 'title', title: '插件名称', align: 'center'}
        , {field: 'version', title: '版本号', align: 'center', width: 100}
        , {field: 'author', title: '作者', align: 'center', width: 100}
        , {field: 'intro', title: '简介'}
        , {field: 'status', title: '状态', templet: '#statusTpl', align: 'center', width: 100}
        , {fixed: 'right', title: '操作', toolbar: '#barDemo', align: 'left', width: 130}
      ]]
      , id: 'testReload'
      , page: false
    });
    var $ = layui.$, active = {
      reload: function () {
        //执行重载
        table.reload('testReload', {
          page: {curr: 1},
        });
      }
    };

    $('.hui-form-search .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    $('.hui-form-search .reset').on('click', function () {
      window.location.reload();
    });

    //监听行工具事件
    table.on('toolbar(admin_table)', function (obj) {
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });

  });
</script>
</body>
</html>
